Shapefile doc and reader fixes. (#165)
authortsteven4 <tsteven4@users.noreply.github.com>
Thu, 26 Apr 2018 17:14:55 +0000 (11:14 -0600)
committerGitHub <noreply@github.com>
Thu, 26 Apr 2018 17:14:55 +0000 (11:14 -0600)
Don't cram different parts of polylines into one route, they
may not be connected.
Add documentation on transformation of coordinate systems that
may be required for GPSBabel usage of shapefiles.

shape.cc
xmldoc/formats/shape.xml

index 7ebb4f9046e18c718613848c92f431f03956787c..0c79a8db835bb1c174bdd68ccd424a26df0b25df 100644 (file)
--- a/shape.cc
+++ b/shape.cc
@@ -65,17 +65,17 @@ arglist_t shp_args[] = {
 /************************************************************************/
 
 SHPHandle SHPAPI_CALL
-SHPOpenGpsbabel( const QString& pszLayer, const char * pszAccess )
+SHPOpenGpsbabel(const QString& pszLayer, const char* pszAccess)
 
 {
-    SAHooks sHooks;
+  SAHooks sHooks;
 
 #ifdef SHPAPI_UTF8_HOOKS
-    SASetupUtf8Hooks( &sHooks );
-    return SHPOpenLL( pszLayer.toUtf8().constData(), pszAccess, &sHooks );
+  SASetupUtf8Hooks(&sHooks);
+  return SHPOpenLL(pszLayer.toUtf8().constData(), pszAccess, &sHooks);
 #else
-    SASetupDefaultHooks( &sHooks );
-    return SHPOpenLL( qPrintable(pszLayer), pszAccess, &sHooks );
+  SASetupDefaultHooks(&sHooks);
+  return SHPOpenLL(qPrintable(pszLayer), pszAccess, &sHooks);
 #endif
 
 }
@@ -88,17 +88,17 @@ SHPOpenGpsbabel( const QString& pszLayer, const char * pszAccess )
 /************************************************************************/
 
 SHPHandle SHPAPI_CALL
-SHPCreateGpsbabel( const QString& pszLayer, int nShapeType )
+SHPCreateGpsbabel(const QString& pszLayer, int nShapeType)
 
 {
-    SAHooks sHooks;
+  SAHooks sHooks;
 
 #ifdef SHPAPI_UTF8_HOOKS
-    SASetupUtf8Hooks( &sHooks );
-    return SHPCreateLL( pszLayer.toUtf8().constData(), nShapeType, &sHooks );
+  SASetupUtf8Hooks(&sHooks);
+  return SHPCreateLL(pszLayer.toUtf8().constData(), nShapeType, &sHooks);
 #else
-    SASetupDefaultHooks( &sHooks );
-    return SHPCreateLL( qPrintable(pszLayer), nShapeType, &sHooks );
+  SASetupDefaultHooks(&sHooks);
+  return SHPCreateLL(qPrintable(pszLayer), nShapeType, &sHooks);
 #endif
 
 }
@@ -108,19 +108,19 @@ SHPCreateGpsbabel( const QString& pszLayer, int nShapeType )
 /*                                                                      */
 /*      Open a .dbf file.                                               */
 /************************************************************************/
-   
+
 DBFHandle SHPAPI_CALL
-DBFOpenGpsbabel( const QString& pszFilename, const char * pszAccess )
+DBFOpenGpsbabel(const QString& pszFilename, const char* pszAccess)
 
 {
-    SAHooks sHooks;
+  SAHooks sHooks;
 
 #ifdef SHPAPI_UTF8_HOOKS
-    SASetupUtf8Hooks( &sHooks );
-    return DBFOpenLL( pszFilename.toUtf8().constData(), pszAccess, &sHooks );
+  SASetupUtf8Hooks(&sHooks);
+  return DBFOpenLL(pszFilename.toUtf8().constData(), pszAccess, &sHooks);
 #else
-    SASetupDefaultHooks( &sHooks );
-    return DBFOpenLL( qPrintable(pszFilename), pszAccess, &sHooks );
+  SASetupDefaultHooks(&sHooks);
+  return DBFOpenLL(qPrintable(pszFilename), pszAccess, &sHooks);
 #endif
 
 }
@@ -132,17 +132,17 @@ DBFOpenGpsbabel( const QString& pszFilename, const char * pszAccess )
 /************************************************************************/
 
 DBFHandle SHPAPI_CALL
-DBFCreateExGpsbabel( const QString& pszFilename, const char* pszCodePage )
+DBFCreateExGpsbabel(const QString& pszFilename, const char* pszCodePage)
 
 {
-    SAHooks sHooks;
+  SAHooks sHooks;
 
 #ifdef SHPAPI_UTF8_HOOKS
-    SASetupUtf8Hooks( &sHooks );
-    return DBFCreateLL( pszFilename.toUtf8().constData(), pszCodePage , &sHooks );
+  SASetupUtf8Hooks(&sHooks);
+  return DBFCreateLL(pszFilename.toUtf8().constData(), pszCodePage , &sHooks);
 #else
-    SASetupDefaultHooks( &sHooks );
-    return DBFCreateLL( qPrintable(pszFilename), pszCodePage , &sHooks );
+  SASetupDefaultHooks(&sHooks);
+  return DBFCreateLL(qPrintable(pszFilename), pszCodePage , &sHooks);
 #endif
 
 }
@@ -154,10 +154,10 @@ DBFCreateExGpsbabel( const QString& pszFilename, const char* pszCodePage )
 /************************************************************************/
 
 DBFHandle SHPAPI_CALL
-DBFCreateGpsbabel( const QString& pszFilename )
+DBFCreateGpsbabel(const QString& pszFilename)
 
 {
-    return DBFCreateExGpsbabel( pszFilename, "LDID/87" ); // 0x57
+  return DBFCreateExGpsbabel(pszFilename, "LDID/87");   // 0x57
 }
 
 static
@@ -321,17 +321,28 @@ my_read(void)
     case SHPT_ARC:
     case SHPT_ARCZ:
     case SHPT_ARCM: {
-      route_head* routehead = route_head_alloc();
-      routehead->rte_name = name;
-      route_add_head(routehead);
-      for (int j = 0; j < shp->nVertices; j++) {
-        wpt = new Waypoint;
-        wpt->latitude = shp->padfY[j];
-        wpt->longitude = shp->padfX[j];
-        if (hasZ) {
-          wpt->altitude = shp->padfZ[j];
+// A part is a connected sequence of two or more points.
+// Parts may or may not be connected to one another.
+// Parts may or may not intersect one another.
+      for (int part=0; part < shp->nParts; part++) {
+        route_head* routehead = route_head_alloc();
+        routehead->rte_name = name;
+        route_add_head(routehead);
+        int endVertex;
+        if (part < (shp->nParts - 1)) {
+          endVertex = shp->panPartStart[part+1];
+        } else {
+          endVertex = shp->nVertices;
+        }
+        for (int j = shp->panPartStart[part]; j < endVertex; j++) {
+          wpt = new Waypoint;
+          wpt->latitude = shp->padfY[j];
+          wpt->longitude = shp->padfX[j];
+          if (hasZ) {
+            wpt->altitude = shp->padfZ[j];
+          }
+          route_add_wpt(routehead, wpt);
         }
-        route_add_wpt(routehead, wpt);
       }
       break;
     }
index caa017c10be3a5e6b3a079b3828dc07e95041249..463d3c501afc6d794292f0abeb04fc930f189a96 100644 (file)
@@ -11,6 +11,8 @@ When passing a file name for a set of shape files the name of any of the files f
 </para>
 <para>
 On read any projection format in a .prj file will be ignored.  This may or may not result in a misinterpretation of the data.
+GPSBabel expects the coordinate system used in the shapefile to be a Geographic Coordinate System with units in decimal degrees measuring degrees of longitude (x-coordinates) and degrees of latitude (y-coordinates), e.g. WGS 84.
+To transform from the spatial reference system described in the .prj file to the Geographic Coordinate System WGS 84 you can use the GDAL utility ogr2ogr, e.g. "ogr2ogr -t_srs EPSG:4326 output.shp input.shp".
 </para>
 <para>
 On read an attempt will be made to check the code page used by the .dbf file and